<?php  
$pPageIsPublic = false;
include '../_common.php';
	
$_SESSION["m1"]	= "restaurant";
$_SESSION["m2"] = 'restaurant-list';
$objName="Menu"; $objUrl="categoria"; $objTitle="Men&uacute;";

$pTitle  = "Nuevo {$objTitle}";
$pButton = 'Guardar';
$action  = 'add';
$id 	 = intval($_REQUEST['id']);
$pid 	 = intval($_REQUEST['pid']);
$seo	 = NULL;


$objLoad = new Menu();
$objLoad ->setUid($id);
if ($objLoad ->load()) {
	$pTitle  = "Editar {$objTitle}";
	$pButton = 'Actualizar';
	$action  = 'edit';
	$pid = $objLoad ->categoria ->id;
	
	if ($_GET['action']=='del') {
		$objLoad ->removeFile('img');
		$message = "Imagen ha sido eliminado.";  
	}
}

if (isset($_POST['submit'])) {
	$objLoad ->setAuto($_POST);
	$objLoad ->uploadFile('ifile', 'img');
	$objLoad ->categoria ->id = $_POST['pid'];
	$objLoad ->_caracteristica = $_POST["caracteristicaId"];
	if ($_POST['action'] == 'edit') {
		$objLoad ->getConnection();
		$objLoad ->setUid($id);
		$objLoad ->update();
		Tzn::redirect("{$objUrl}-add.php?id={$objLoad ->categoria ->id}&tab=menu", "{$objTitle} ha sido actualizada.");
	} elseif ($_POST['action'] == 'add') {
		$objLoad ->add();
		Tzn::redirect("{$objUrl}-add.php?id={$objLoad ->categoria ->id}&tab=menu", "{$objTitle} ha sido registrado.");
	}
}
?>
<?php include("header.php"); ?>
<?php
	$tabs 	= array('config' => 1);
	$selTab = $tabs[$_REQUEST['tab']] ? $tabs[$_REQUEST['tab']] : 0;
?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();	
	$("#price").maskMoney(/*{symbol:'S/. ', symbolStay: false}*/);
	$('#caracteristicaId').multiSelect({ selectAll: false, oneOrMoreSelected: '*', noneSelected : 'Seleccionar caracter&iacute;sticas del men&uacute;' });
	$('#content-tabs').tabs({
		disabled :[<?= !$objLoad ->isLoaded() ? "1" : "" ?>],
		active  : <?= $selTab ?>
	});	
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=menu" > Atras </a></li>
	<li class="noborder" >
		<a class="add" href="<?= $_SERVER["PHP_SELF"] ?>?pid=<?= $pid?>" > Agregar un <?= $objTitle ?> </a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> <?= $objLoad ->isLoaded() ? "- <span class=\"mark\" >\"{$objLoad ->titulo}\"</span>" : "" ?> </h2>
<div id="content-tabs">
		<ul>
			<li><a href="#fragment-1" ><span>Info Men&uacute;</span></a></li>
			<li><a href="#fragment-2"><span>Caracter&iacute;stica del men&uacute;</span></a></li>
		</ul>
<div id="fragment-1" >
	<form action="" method="post" name = "frmMain" id = "frmMain" enctype="multipart/form-data"  >
	<fieldset><legend> Informaci&oacute;n General</legend>
		<table cellpadding="0" cellspacing="0" class="table-form"  >
			<tr>
				<th>Categor&iacute;a: </th>
				<td><?php
				 $tmp = new Categoria();
				 $tmp ->addOrder('orderId ASC');
				Generic::gSelect($tmp, '', ($objLoad ->isLoaded() ? $objLoad ->categoria ->id : $pid) , '--- seleccionar una categor&iacute;a ---', '', 'class="required"', 'pid');    ?></td>
			</tr>
			<tr>
				<th>T&iacute;tulo: </th>
						<td><?php $objLoad ->qText('titulo', '', 'width:548px', 'class="required"');?></td>
					</tr>
					<tr>
						<th>Descripci&oacute;n: </th>
						<td><?php $objLoad ->qTextArea('descripcion', '', 'width:548px;height:60px;', '');?></td>
					</tr>
					<tr>
						<th>Precio: </th>
						<td><?php $objLoad ->qText('precio', '', 'width:86px', 'class="" id="price"');?></td>
					</tr>
					<tr>
					<tr>
						<th>Imagen: </th>
						<td><?php $objLoad ->pFile('ifile', "{$_SERVER['PHP_SELF']}?id={$objLoad ->id}&action=del", 'img', 'img', false) ?></td>
					</tr>
					<tr>
						<th>Detalles del men&uacute;:</th>
						<td><?php $objLoad ->pSelectCheckBoxCaracteristica();  ?></td>
					</tr>
					<tr>
					<tr>
						<th>Estado: </th>
						<td><?php $objLoad ->arrayToSelect($objLoad ->_arrStatus, 'estado', $objLoad ->estado, false, 'width:100px', '');?></td>
					</tr>
				</table>
		</fieldset>
	<div style="margin-top:10px">
		<input type="hidden" name="id" value="<?php echo $id; ?>" />
		<input type="hidden" name="action" value="<?php echo $action; ?>" />
                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancelar" onClick="window.location.href='<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=menu'" />
                
            </div>
            </form>
	</div>
	<div id="fragment-2" >
			<fieldset><legend> Caracter&iacute;stica del men&uacute; <?= $objLoad ->isLoaded() ? "- {$objLoad ->titulo}" : "" ?>  </legend>
				<?php 
					Common::hFrmFilterAdmin('MenuConfig', 'Caracter&iacute;stica', 'menuconfig', "pid={$objLoad ->id}");
					$objChild  = new MenuConfig();
					$objChild ->loadItems("#orderId ASC", "#estado like '". $chkstatus ."%' AND #menuId='". intval($objLoad ->id) ."'");
					echo "<div id='wrap-list'>" . Common::hSimpleGridV2('MenuConfig', 'Caracter&iacute;stica', 'menuconfig', $objChild, true,
							array(
								'description' => false,
								/*'navs' => array (
										0 => array (
											'custom' => '<p class="sub-nav">&raquo; Precio: <strong>S/.@precio</strong></p>',
										)
								)*/						
								'navs' 		 => array (
										0 => array (
												'title' 	=> 'Items',
												'count'     => 'gMenuConfigDetalleCount',
												'objName' 	=> 'MenuConfigDetalle'
										)
								),												
							)
							, false) . '</div>';
				?>
			</fieldset>
	</div>            
 </div>
</div>
<?php include("footer.php"); ?>